package st.strategy.vo;

import st.base.Sysdate;

/** 黃金交叉 */
public class GoldenCross implements Signal {
	protected double lastLongTermValue;
	protected double lastShortTermValue;
	protected double longTermValue;
	protected double shortTermValue;
	protected Sysdate tradeDate;

	public GoldenCross(TechLine longTerm, TechLine shortTerm,
			Sysdate tradeDate, Stock stock) {
		Sysdate lastTradeDate = tradeDate.add(-1, stock);
		longTermValue = ((SimpleTechValue) longTerm.getValue(tradeDate))
				.getValue();
		shortTermValue = ((SimpleTechValue) shortTerm.getValue(tradeDate))
				.getValue();
		lastLongTermValue = ((SimpleTechValue) longTerm.getValue(lastTradeDate))
				.getValue();
		lastShortTermValue = ((SimpleTechValue) shortTerm
				.getValue(lastTradeDate)).getValue();
		this.tradeDate = tradeDate;
	}

	@Override
	public boolean isAppear() {
		if (lastLongTermValue > lastShortTermValue
				&& shortTermValue > longTermValue) {
			return true;
		}
		return false;
	}

	@Override
	public String toString() {
		return getClass().getSimpleName() + "["
				+ (tradeDate != null ? "tradeDate=" + tradeDate + ", " : "")
				+ "lastShortTermValue=" + lastShortTermValue
				+ ", lastLongTermValue=" + lastLongTermValue
				+ ", shortTermValue=" + shortTermValue + ", longTermValue="
				+ longTermValue + "]";
	}

}
